;;; GNU Guix --- Functional package management for GNU
;;;
;;; Copyright © 2022 ( <paren@disroot.org>
;;;
;;; This file is not part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (guixrus packages himitsu)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system meson)
  #:use-module (guix gexp)
  #:use-module (guix git-download)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (gnu packages freedesktop)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages gnome)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages man)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages python)
  #:use-module ((guixrus packages hare) #:prefix rus:)
  #:use-module ((guixrus packages common hare) #:prefix rus:)
  #:use-module ((guixrus contributors) #:prefix contributor:))

(define-public himitsu
  (package
   (name "himitsu")
   (version "0.1")
   (source (origin
            (method git-fetch)
            (uri (git-reference
                  (url "https://git.sr.ht/~sircmpwn/himitsu")
                  (commit version)))
            (file-name (git-file-name name version))
            (sha256
             (base32
              "0sd25s6553h8cm1hdvs8pgpssfa1i9bcn4bmd9ymif4cj8656c5p"))))
   (build-system gnu-build-system)
   (arguments
    (list #:make-flags #~(list (string-append "PREFIX=" #$output))
          #:phases
          #~(modify-phases %standard-phases
              (delete 'configure)
              (add-before 'build 'set-harecache
                (lambda _
                  (setenv "HARECACHE" ".cache"))))))
   (inputs (list rus:hare-toolchain))
   (native-inputs (list scdoc))
   (home-page "https://himitsustore.org/")
   (synopsis "Secure key/value store")
   (description
    "Himitsu is a simple secret storage system written in Hare.  It is suitable
for storing passwords, private keys, and so on.

Be aware that due to its work-in-progress status, neither this project nor the
underlying cryptograhic implementation has been independently audited.")
   (license license:gpl3)
   (properties `((maintainers . (,contributor:unmatched-paren))))))

(define-public himitsu-ssh
  (package
   (name "himitsu-ssh")
   (version "0.1")
   (source (origin
            (method git-fetch)
            (uri (git-reference
                  (url "https://git.sr.ht/~sircmpwn/himitsu-ssh")
                  (commit version)))
            (file-name (git-file-name name version))
            (sha256
             (base32
              "194ngkqmrfxs3js594sblg60h4ldbg333rwvfk061jb497387hni"))))
   (build-system gnu-build-system)
   (arguments
    (list #:make-flags #~(list (string-append "PREFIX=" #$output))
          #:phases
          #~(modify-phases %standard-phases
              (delete 'configure)
              (add-before 'build 'set-harecache
                (lambda _
                  (setenv "HARECACHE" ".cache"))))))
   (home-page "https://himitsustore.org")
   (inputs (list rus:hare-toolchain))
   (native-inputs (list scdoc rus:hare-ssh himitsu))
   (synopsis "SSH integration for Himitsu")
   (description
    "This package provides integration for the Himitsu secret storage system
with Secure Sockets Shell (SSH).")
   (license license:gpl3)
   (properties `((maintainers . (,contributor:unmatched-paren))))))

(define-public hiprompt-gtk-py
  (let ((commit "f74499302bdd6558d4644c25e15c9b5c482270ea")
        (revision "0"))
    (package
     (name "hiprompt-gtk-py")
     (version (git-version "0.0.0" revision commit))
     (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://git.sr.ht/~sircmpwn/hiprompt-gtk-py")
                    (commit commit)))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "17kmg9rw5n5ibmahb4kdprpmhw2yaq92z50ps04sjm8rmvp21xpy"))))
     (build-system meson-build-system)
     (arguments
      (list #:glib-or-gtk? #t
            #:phases
            #~(modify-phases %standard-phases
                (add-after 'unpack 'skip-gtk-update-icon-cache
                  (lambda _
                    (substitute* "build-aux/meson/postinstall.py"
                      (("gtk-update-icon-cache") (which "true")))))
                (add-after 'install 'wrap-programs
                  (lambda* (#:key outputs #:allow-other-keys)
                    (let ((out (assoc-ref outputs "out")))
                      (wrap-program (string-append out "/bin/hiprompt-gtk")
                        `("GI_TYPELIB_PATH" =
                          (,(getenv "GI_TYPELIB_PATH")))
                        `("GUIX_PYTHONPATH" =
                          (,(getenv "GUIX_PYTHONPATH"))))))))))
     (inputs (list glib gtk+ gtk-layer-shell python-pygobject))
     (native-inputs (list desktop-file-utils
                          (list glib "bin")
                          gobject-introspection
                          python))
     (home-page "https://himitsustore.org")
     (synopsis "GTK-based prompt GUI for Himitsu")
     (description
      "This package provides a GTK-based prompter for the Himitsu secret storage
system.")
     (license license:gpl3)
     (properties `((maintainers . (,contributor:unmatched-paren)))))))

(define-public himitsu-keyring
  (package
   (name "himitsu-keyring")
   (version "0.1.0")
   (source (origin
            (method git-fetch)
            (uri (git-reference
                  (url "https://git.sr.ht/~martijnbraam/keyring")
                  (commit version)))
            (file-name (git-file-name name version))
            (sha256
             (base32
              "1asnsfni7aypdvrv5cc1dnw8g3vwh5l1r1q38jvf6g4z5mzl5hvj"))))
   (build-system meson-build-system)
   (arguments
    (list #:glib-or-gtk? #t
          #:phases
          #~(modify-phases %standard-phases
              (add-after 'unpack 'skip-gtk-update-icon-cache
                (lambda _
                  (substitute* "build-aux/meson/postinstall.py"
                    (("gtk-update-icon-cache") (which "true")))))
              (add-after 'install 'wrap-programs
                (lambda* (#:key outputs #:allow-other-keys)
                  (let ((out (assoc-ref outputs "out")))
                    (wrap-program (string-append out "/bin/himitsu-keyring")
                      `("GI_TYPELIB_PATH" =
                        (,(getenv "GI_TYPELIB_PATH")))
                      `("GUIX_PYTHONPATH" =
                        (,(getenv "GUIX_PYTHONPATH"))))))))))
   (inputs
    (list adwaita-icon-theme
          hicolor-icon-theme
          glib
          gtk+
          libhandy
          python-pygobject))
   (native-inputs
    (list desktop-file-utils
          (list glib "bin")
          gobject-introspection
          pkg-config
          python))
   (home-page "https://git.sr.ht/~martijnbraam/keyring")
   (synopsis "Graphical secret manager using Himitsu")
   (description
    "This package provides a GTK-based graphical secret manager backed by the
Himitsu secure key/value store.")
   (license license:gpl3)
   (properties `((maintainers . (,contributor:unmatched-paren))))))
